package com.chen.proxyReviw.util;

import java.lang.reflect.Proxy;

public class ProxyUtils {

    public static <T> T createProxyInstance(T t) {
         return (T) Proxy.newProxyInstance(
                ProxyUtils.class.getClassLoader(),
                t.getClass().getInterfaces(),
                 (proxy, method, args) -> {
                     // 获取时间
                     long start = System.currentTimeMillis();
                     Object result = method.invoke(t, args);
                     long end = System.currentTimeMillis();
                     System.out.println(method.getName()+"方法耗时"+(end-start)+"ms");
                     return result;
                 }
         );
    }
}
